package com.mercury.kafka.serialization;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.serialization.Serializer;

import java.io.Serializable;
import java.util.Map;


/**
 * @author mercury
 * kafka生产者自定义序列化
 */
@Slf4j
public class KafkaProducerSerializer implements Serializer<Object> {

    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {

    }

    @Override
    public byte[] serialize(String s, Object o) {
        return SerializationUtils.serialize((Serializable) o);
    }

    @Override
    public byte[] serialize(String topic, Headers headers, Object data) {
        return SerializationUtils.serialize((Serializable) data);
    }

    @Override
    public void close() {
    }

}